#define WIN32_LEAN_AND_MEAN



#include <stdio.h>
#include "MySocket.h"
#include "message.h"

#define MAXSIZE 512
#define DEFAULT_PORT "27015"

int __cdecl main(int argc, char **argv) 
{
	CConnectSocket connectSocket;
    char sendbuf[MAXSIZE];
    int iResult;
   
    if (argc != 2) {
        printf("usage: %s server-name\n", argv[0]);
        return 1;
    }

	if (!WndSocketStartup()) {
		printf("start up window socket fail\n");
		return 1;
	}
	

	if(connectSocket.Connect(argv[1], DEFAULT_PORT) == false) {
		printf("connect failed with error: %d\n", WSAGetLastError());
		WndSocketCleanup();
		return 1;
	}
	
    
	while(true) {
		PM_CHOICE pChoice = new M_CHOICE;
		pChoice->opcode = MSG_CHOICE;

		printf("Nickname? : ");
		scanf("%c", &pChoice->choice);
		iResult = connectSocket.Send((void*) pChoice, (int)MSGSIZE);
		if (iResult == SOCKET_ERROR) {
			printf("send failed with error: %d\n", WSAGetLastError());
			WndSocketCleanup();
			return 1;
		}
		//if (strcmpi(pMsgRegister->nickname, "exit") == 0)
		//		break;
	}

   WndSocketCleanup();
   return 0;
}